# -*- coding: utf-8 -*-

"""
DateTime   : 2020/12/18 16:44
Author     : ZhangYafei
Description: 
"""
import logging
import traceback


def method1():
    try:
        res = 2 / 0
        print(res)
    except Exception as e:
        print('str: ', e)  # str:  division by zero
        print('repr: ', repr(e)) # repr:  ZeroDivisionError('division by zero')

def method2():
    try:
        res = 2 / 0
        print(res)
    except Exception as e:
        logging.exception(e)
        """
        ERROR:root:division by zero
        Traceback (most recent call last):
          File "D:/python/Python之路/10 异常处理/打印异常信息.py", line 21, in method2
            res = 2 / 0
        ZeroDivisionError: division by zero
        """

def method3():
    try:
        res = 2 / 0
        print(res)
    except Exception:
        traceback.print_exc()
        """
        Traceback (most recent call last):
          File "D:/python/Python之路/10 异常处理/打印异常信息.py", line 36, in method3
            res = 2 / 0
        ZeroDivisionError: division by zero
        """


if __name__ == '__main__':
    method1()
    method2()
    method3()

